package gameadminlogic

import (
	"context"
	"go.uber.org/zap"
	"navi-mumbai/app/rpc/game/internal/svc"
	"navi-mumbai/app/rpc/game/pb"
	"navi-mumbai/app/rpc/model/pg/game"
	"navi-mumbai/common/key/dbkey"
	"navi-mumbai/common/utils"
	"navi-mumbai/common/xerr"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGameProviderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddGameProviderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGameProviderLogic {
	return &AddGameProviderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加游戏供应商
func (l *AddGameProviderLogic) AddGameProvider(in *pb.AddGameProviderReq) (*pb.AddGameProviderResp, error) {
	defer utils.RecoverPanic()

	gp := game.GameProvider{
		ProviderName: in.ProviderName,
		ProviderId:   in.ProviderId,
		State:        dbkey.Enable,
		Logo:         in.Logo,
	}
	_, err := l.svcCtx.GameProviderModel.Insert(l.ctx, &gp)
	if err != nil {
		l.Logger.Errorf("err == ", zap.Error(err))
		return nil, xerr.NewGrpcErrCodeMsg(xerr.DbError, err.Error())
	}
	return &pb.AddGameProviderResp{}, nil
}
